package com.xw.singleton;

/**
 * @author: xw
 * @create: 2022/9/13 17:56
 * @description: 懒汉模式
 */
public class Code02_SingletonLazy {
    private  static Code02_SingletonLazy INSTANCE;

    private Code02_SingletonLazy(){}

    public static Code02_SingletonLazy getInstance(){
        if(null == INSTANCE){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            INSTANCE = new Code02_SingletonLazy();
        }
        return INSTANCE;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            new Thread(()->
                    System.out.println(Code02_SingletonLazy.getInstance().hashCode())
                    ).start();
        }
    }
}
